<?
function DateDiff($interval, $date1, $date2) { 

// @See: It gets the number of the seconds in the one of the 2nd period day interval.
$time_difference = $date2 - $date1; 
switch ($interval) {
case "w": $retval = bcdiv($time_difference, 604800); break; 
case "d": $retval = bcdiv($time_difference, 86400); break; 
case "h": $retval = bcdiv($time_difference, 3600); break; 
case "n": $retval = bcdiv($time_difference, 60); break; 
case "s": $retval = $time_difference; break; 
} 

return $retval;
} 
define("_ROOT",".");
set_time_limit(0);
error_reporting(0);
include _ROOT."/mainfile.php";
include _ROOT."/class/functions.php";
$xnadb = $PlusDB->prefix("xna");
$xnanewsdb = $PlusDB->prefix("xna_news");
$sql="select * from $xnadb  where 1";
$rt  = $PlusDB->execute($sql);

while($row = $rt->fetchRow()){
	$done = "no";
	$utime = converttime($row[utime]);

    if (DateDiff("n",$utime,time())<$row["rss_feq"]) break;
    if ($row["update_status"]==true) exit;
    $row["update_status"]=true;
    if($utime=="943891200") $done="yes";
    $xtime = time()-$row["rss_feq"]*60;
    if($utime<$xtime) $done = "yes";
    if($done=="yes"){
	    ob_start();
	    doFetch($row[id]);
    	$msg.=ob_get_contents();
    	ob_get_clean();
    	$msg.="站点编号".$row[id]."更新完成";
    }
    $row["update_status"]=false;
}
$msg=$msg==""?"暂时无更新":$msg;
echo "msg=\"".$msg."\";";

function convertTime($datestr){
	$timestamp = strtotime($datestr);
	return $timestamp;
}
?>